﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using GCELibrary.Current;
using ZF.BLL.ServiceModel;


namespace ZF.WS.UserControls.Index
{
    public partial class expert1 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            var typeList = DictionaryConfig.EExpertType.Where(p => !(p.Key == 3 || p.Key == 4)).ToList();
            this.lvTitle.DataSource = typeList;
            this.lvTitle.DataBind();
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                Dictionary<object, List<object>> dicType =null;
                var cacheKey = "_Index_expert";
                var obj = HttpCache.GetCache(cacheKey);
                if (obj != null)
                {
                    dicType = obj as Dictionary<object, List<object>>;
                }
                else
                {
                    dicType = new Dictionary<object, List<object>>();
                    foreach (var type in typeList)
                    {
                        var list = dc.US_Member.Where(p => p.IsExpert)
                            .Where(p => p.ExpertType == type.Key)
                            .OrderByDescending(p => p.Integral)
                             .Take(9).ToList().Select(p =>
                             (object)new
                             {
                                 Member = p,
                                 EType = DictionaryConfig.EExpertType.FirstOrDefault(t => t.Key == p.ExpertType).Text
                             }).ToList();

                        dicType[type.Key] = list;
                    }

                    SiteInfo.Instance.SetPageCache(cacheKey,dicType);
                }
                
                this.lvList.DataSource = dicType;
                this.lvList.DataBind();

                this.lvTJ_Expert1.DataSource = dc.US_Member.Where(p => p.IsRecommend && p.ExpertType == 1).OrderByDescending(p => p.Integral).Take(12).ToList()
                    .Select(p =>
                             (object)new
                             {
                                 Member = p,
                                 EType = DictionaryConfig.EExpertType.FirstOrDefault(t => t.Key == p.ExpertType).Text
                             }).ToList();
                this.lvTJ_Expert1.DataBind();

                this.lvTJ_Expert2.DataSource = dc.US_Member.Where(p => p.IsRecommend && p.ExpertType == 2).OrderByDescending(p => p.Integral).Take(12).ToList()
                    .Select(p =>
                             (object)new
                             {
                                 Member = p,
                                 EType = DictionaryConfig.EExpertType.FirstOrDefault(t => t.Key == p.ExpertType).Text
                             }).ToList();
                this.lvTJ_Expert2.DataBind();
                var artList = dc.Sys_Service.Where(p=>p.Type==(int)ServiceType.FSYW1).OrderByDescending(p => p.ServiceId).ToList();
               
                this.lvArticle.DataSource = artList.Take(8);
                this.lvArticle.DataBind();


  




            }


            using (var dc = SiteInfo.CreateDBDataContext())
            {

                List<object> list = null;

                var cacheKey = "_index_Blog";
                var obj = HttpCache.GetCache(cacheKey);
                if (obj != null)
                {
                    list = obj as List<object>;
                }
                else
                {
                    list = dc.Sys_SiteBlog
                     .OrderByDescending(p => p.OrderId).Take(20).ToList().Select(p => (object)p).ToList();
                    SiteInfo.Instance.SetPageCache(cacheKey, list);
                }


                this.lvBlog.DataSource = list.Take(12);
                this.lvBlog.DataBind();

            }
            
        }

       
    }
}